<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript">
        var ws

        function WebSocketTest() {
            if ("WebSocket" in window) {
                var msgSpan = document.getElementById("msg");
                var id = document.getElementById("orderid").innerText;
                if (!id) {
                    id = document.getElementById("orderid").innerHTML;
                }
                // 打开一个 web socket
                ws = new WebSocket("wss://securit.qfjava.cn/websocket/websocket/" + id);

                ws.onopen = function () {
                    // Web Socket 已连接上，使用 send() 方法发送数据
                    //ws.send("发送lainjie数据");
                    // alert("数据发送中...");
                    msgSpan.innerHTML = "建立连接了";
                };

                ws.onmessage = function (evt) {
                    var received_msg = evt.data;
                    // alert("数据已接收..."+received_msg);
                    msgSpan.innerHTML = received_msg;
                    if (1 == received_msg) {
                        location.href="http://www.163.com"
                    }
                };

                ws.onclose = function () {
                    // 关闭 websocket
                    // alert("连接已关闭...");
                    msgSpan.innerHTML = "连接已关闭...";
                };
            } else {
                // 浏览器不支持 WebSocket
                alert("您的浏览器不支持 WebSocket!");
            }
        }


    </script>
</head>
<body>
订单 id:<p th:text="${orderid}" id="orderid"></p>
<br>
请扫码支付
<img th:src="${picurl}">
<br><br><br>
<span id="msg" style="color:red"></span>
</body>

<script type="text/javascript">

    window.onload = WebSocketTest();
</script>
</html>